'use strict';

import fs from "fs";
import path from "path";
import Base from './base.js';

export default class extends Base {
  /**
   * index action
   * @return {Promise} []
   */
  indexAction(){
    //auto render template file index_index.html
    this.success({dd:'dd'});
  }

  //上传图片接口
	async uploadAction(){
		// console.log(think)
		let file = think.extend({}, this.file('file'));

		//C:\\Users\\Administrator\\Desktop\\ZNews\\runtime\\upload\\eGaIypGOGTCpEvHROq3PwFDz.docx
		let filepath = file.path;
		let newpath = liFormatDate(new Date().toLocaleDateString());
		let uploadPath = think.UPLOAD_PATH + '/pics/' + newpath;

		// C:\Users\Administrator\Desktop\ZNews\www/static/upload/pics/2017/05/05
		think.mkdir(uploadPath);
		//eGaIypGOGTCpEvHROq3PwFDz.docx
		let basename = path.basename(filepath);
		fs.renameSync(filepath, uploadPath + '/' + basename);


		this.success({path: "/static/upload/pics/" + newpath + basename});
	}
}